#!/bin/bash

scriptPath=$(dirname $0);
logPath=$(pwd)


# --- create database	
#	sh $scriptPath/createDatabase.sh;

echo ".. calculating overhead"

# SUCCESS TO NODES
# query="select count(*) from overheadHelp WHERE eventName='EVENT_TYPE_DATAOBJECT_SEND_SUCCESSFUL' AND nodeId2!='-' AND nodeId2!='[Unk' AND nodeId2!='3ced';"
query="select count(*) from events WHERE eventName='EVENT_TYPE_DATAOBJECT_SEND';"
successToNodes=$(sqlite3 -batch -separator ' ' trace.sqlite "$query")

# SUCCESS > NEW
# query="select count(*) from overheadHelp as send LEFT JOIN overheadHelp as receive ON send.dobjId=receive.dobjId AND send.nodeId2=receive.nodeId1 WHERE send.eventName='EVENT_TYPE_DATAOBJECT_SEND_SUCCESSFUL' AND receive.eventName='EVENT_TYPE_DATAOBJECT_NEW';"
# query="select count(*) from overheadHelp WHERE eventName='EVENT_TYPE_DATAOBJECT_RECEIVED' AND receive.eventName='EVENT_TYPE_DATAOBJECT_NEW';"
# query="select count(*) from overheadHelp as send LEFT JOIN overheadHelp as receive WHERE send.eventName='EVENT_TYPE_DATAOBJECT_SEND_SUCCESSFUL' AND receive.eventName='EVENT_TYPE_DATAOBJECT_NEW';"
query="select count(*) from events WHERE eventName='EVENT_TYPE_DATAOBJECT_RECEIVED';"
successNew=$(sqlite3 -batch -separator ' ' trace.sqlite "$query")

# NEW > SUCCESS TO LUCKYME
# query="select count(*) from overheadHelp as a LEFT JOIN overheadHelp as b ON a.dobjId=b.dobjId AND a.nodeId1=b.nodeId1 WHERE a.eventName='EVENT_TYPE_DATAOBJECT_NEW' AND b.eventName='EVENT_TYPE_DATAOBJECT_SEND_SUCCESSFUL' AND b.nodeId2='3ced';"
# newToLuckyMe=$(sqlite3 -batch -separator ' ' trace.sqlite "$query")

# --- print
echo "EXPERIMENT | SUCCESS TO NODES | TOTAL | SUCCESS > NEW (ratio) "
# echo $expriment "|" $successToNodes "|" $successNew "("$[100 * $successNew / $successToNodes] "%) |" $newToLuckyMe "("$[100 * $newToLuckyMe / $successNew] "%)"
echo  $experiment "|" $successNew "|" $successToNodes "|""("$[100 * $successNew / $successToNodes] "%)"

cd ..

